define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activity_take/index' + location.search,
                    // add_url: 'activity_take/add',
                    // edit_url: 'activity_take/edit',
                    // del_url: 'activity_take/del',
                    multi_url: 'activity_take/multi',
                    import_url: 'activity_take/import',
                    table: 'activity_take',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'nick', title: __('Uid') },
                        { field: 'active_typs', title: __('Active_typs'), searchList: { "1": __('Active_typs 1'), "2": __('Active_typs 2') }, formatter: Table.api.formatter.normal },
                        { field: 'start', title: __('Start') },
                        { field: 'ends', title: __('Ends') },
                        { field: 'stands_time', title: __('Stands_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'tranAmt', title: __('Tranamt'), operate: 'BETWEEN' },
                        { field: 'standsAmt', title: __('Standsamt'), operate: 'BETWEEN' },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'is_stands', title: __('Is_stands'), searchList: { "1": __('Is_stands 1'), "2": __('Is_stands 2') }, formatter: Table.api.formatter.normal },
                        { field: 'process', title: __('Process'), searchList: { "1": __('Process 1'), "2": __('Process 2'), "3": __('Process 3') }, formatter: Table.api.formatter.normal },
                        { field: 'process_time', title: __('Process_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'username', title: __('Process_id') },
                        { field: 'nickname', title: __('Process_uid') },
                        { field: 'alloct', title: __('Allot_uid') },
                        { field: 'allot_time', title: __('Allot_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'is_allot', title: __('Is_allot'), searchList: { "1": __('Is_allot 1'), "2": __('Is_allot 2') }, formatter: Table.api.formatter.normal },
                        { field: 'is_due', title: __('Is_due'), searchList: { "1": __('Is_due 1'), "2": __('Is_due 2') }, formatter: Table.api.formatter.normal },
                        { field: 'update_time', title: __('Update_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                    name: 'confirm',
                                    title: "处理",
                                    text: __('处理'),
                                    icon: 'fa fa-check',
                                    classname: 'btn btn-success btn-xs btn-detail btn-dialog',
                                    url: 'activity_take/confirm',
                                    extend: 'data-area=\'["100%", "100%"]\''
                                }
                                // , {
                                //     name: 'receive',
                                //     title: "分配",
                                //     text: __('分配'),
                                //     icon: 'fa fa-check',
                                //     classname: 'btn btn-primary btn-xs btn-detail btn-dialog',
                                //     url: 'activity_take/receive',
                                //     extend: 'data-area=\'["100%", "100%"]\'',
                                //     hidden: function(data, ret) {
                                //         if (data.status == 2) {
                                //             return false;
                                //         } else {
                                //             return true;
                                //         }
                                //     }
                                // }
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        confirm: function() {
            Controller.api.bindevent();
        },
        receive: function() {
            $(document).on('change', "#c-type", function() {
                const val = $(this).val();
                if (val == 1) {
                    $(".stock").show();
                } else if (val == 2) {
                    $(".stock").hide();
                }
            });

            $(document).on('change', "#c-to_type", function() {
                const val = $(this).val();
                if (val == 1) {
                    $("#company").show();
                    $("#user").hide();
                } else if (val == 2) {
                    $("#company").hide();
                    $("#user").show();
                }
            });

            $(document).on('change', "#c-data_type", function() {
                const val = $(this).val();
                if (val == 1) {
                    $("#file_url").show();
                    $("#sn").hide();
                } else if (val == 2) {
                    $("#file_url").hide();
                    $("#sn").show();
                }
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});